
!(function(doc, win) {
	var userAgentInfo = navigator.userAgent;
	var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
	var flag = true;
	for (var v = 0; v < Agents.length; v++) {
		if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; }
	}
	if (flag) {
		var docEle = doc.documentElement,
		evt = "onorientationchange" in window ? "resize" : "orientationchange",
		fn = function() {
			var width = 500;
			width && (docEle.style.fontSize = 100 * (width / 750) + "px");
		};
		win.addEventListener(evt, fn, false);
		doc.addEventListener("DOMContentLoaded", fn, false);

		$('.wrapper').css({'width': '500px', 'margin': '0 auto'});
		$('.nav').css({'width': '500px', 'left': '50%', 'transform': 'translateX(-50%)'});
		$('.jh-container').css({'width': '500px', 'left': '50%', 'transform': 'translateX(-50%)'});
		$('.pos-box').addClass('none');
		$('body').css('background', '#9b9fa3');
	} else {
		return;
	}
}(document, window));
// 以上部分为了暂时在pc上展示样式 后期更改

var activityNo = getCookie('activity_no');

$('.mes-one').removeClass('row-start-center').addClass('row-start-start');

//cookie
function setCookie(name, value, iDay){
	var oDate=new Date();
	oDate.setDate(oDate.getDate()+iDay);
	document.cookie = name + '=' + encodeURIComponent(value) + ';expires=' + oDate;
}
function getCookie(name){
	var arr = document.cookie.split('; ');
	var i = 0;
	for(i = 0;i < arr.length;i++) {
		var arr2 = arr[i].split('=');
		if(arr2[0] == name) {
			var getC = decodeURIComponent(arr2[1]);
			return getC;
		}
	}
	return '';
}
function removeCookie(name) {
	setCookie(name, '1', -1);
}

// 判断浏览器
var browser = {
	versions : function() {
		var u = navigator.userAgent, app = navigator.appVersion;
		return {//移动终端浏览器版本信息
			trident : u.indexOf('Trident') > -1, //IE内核
			presto : u.indexOf('Presto') > -1, //opera内核
			webKit : u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
			gecko : u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
			mobile : !!u.match(/AppleWebKit.*Mobile.*/)
			|| !!u.match(/AppleWebKit/), //是否为移动终端
			ios : !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
			android : u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
			iPhone : u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
			iPad: u.indexOf('iPad') > -1, //是否iPad
			webApp : u.indexOf('Safari') == -1,//是否web应该程序，没有头部与底部
			google:u.indexOf('Chrome')>-1 ,
			weiChat: u.indexOf('MicroMessenger') > -1 || u.indexOf('micromessenger') > -1
		};
	}(),
}

// 取参数方法  例：$.getUrlVars('activityNo')
$.extend({
	getUrlVars: function () {
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		};
		return vars;
	},
	getUrlVar: function (name) {
		return $.getUrlVars()[name];
	}
});


// 哪种设备打开
if(browser.versions.weiChat){
	if(getCookie("wx_login") == "undefined" || getCookie("wx_login") == "" || getCookie("wx_login") == "false"){
		setCookie("iswx","1");
		window.location.reload();
	}else if(getCookie("wx_login") == "true"){
		setCookie("iswx","1");
	}
}else if(browser.versions.mobile){
	setCookie("iswx","0");
}else{
	setCookie("iswx","0");
}

function ifUndefine(str){
	if(typeof(str)=="undefined"){
		return "";
	}else{
		return str;
	}
}
// 获取链接参数
function GetSearchParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
	var r = window.location.search.substr(1).match(reg);
	if (r!=null) return (r[2]); return null;
}
// 获取链接路劲 得到参数
function getNo() {
	var path = window.location.pathname;
	var activityNo = path.split('/')[path.split('/').length - 1];
	return activityNo;
}

// 长按
$.fn.longPress = function(fn) {
	var timeout = undefined;
	var $this = this;
	for(var i = 0;i<$this.length;i++){
		$this[i].addEventListener('touchstart', function(event) {
			timeout = setTimeout(fn, 800);
		}, false);
		$this[i].addEventListener('touchend', function(event) {
			clearTimeout(timeout);
		}, false);
	}
}

// 提示弹层
function alertWindow(title, mes, wrap) {
	if(mes == '') {
		$(wrap).find('.alert-mes').addClass('none');
	}else {
		$(wrap).find('.alert-mes').removeClass('none');
		$(wrap).find('.alert-mes').html(mes);
	}
	$(wrap).find('.alert-title').html(title);
	$(wrap).removeClass('none');
}
// 关闭 弹出
$('.alert-button').click(function() {
	$('.alert-common').addClass('none');
})

// 阻止默认事件
function touchModal(event){
	var event = event || window.event;
	event.preventDefault();
	return false;
}

// 更改皮肤
function changeTheme(id_){
	if(id_ == 2){
		//白色版本
		$('body, html, .picWait, h2, .wrapper, .activityDetail-p, .time-icon, .place-icon, .sponsorBox, .guestBox').addClass('white');

		$('.guestMasking,.navMasking').attr('src','http://static.qiezipai.cn/wechat/live/image/live4/cusmasking-white.png');
		$('.sponsor').css('background-image','url(http://static.qiezipai.cn/wechat/live/image/live4/sponsorbg-white.png)');
		$('.sponsor-border').removeClass('none');
		$('.guest').css('background-image','url(http://static.qiezipai.cn/wechat/live/image/live4/guestbg-white.png)');

		$('.sponsorTitle, .guestTitle, .sponsorName, .guestName, .line, .lookButton-p, .nav, .navLi, .picLoading').addClass('white');
		$('.triggle-icon').attr('src','http://static.qiezipai.cn/wechat/live/image/live4/triggle-icon-white.png');
		$('.sponsor-container, .guest-container, .mes-container, .sponsor-name, .guest-name, .sponsor-imgBg, .mes-one').addClass('white');
		$('.sponsor-link, .guest-link, .close, .activityDescribe, .videoWrapper, .activityDescribe-p, .navLi-span').addClass('white');
		$('.title-span, .common-p, .cusWebSite, .ewm-p1, .ewm-p2, .homeLink, .videoBox, .changeStyle, .day_title, .arrow_right, .appointment').addClass('white');
		$('.mes-one p, .mes-title, .findMe, .me, .hasVideo-inner, .close-guide, .nav-left, .download-button, .download-icon, .download-img, .juzi-logo').addClass('white');
		$('.ewmImg').attr('src','http://static.qiezipai.cn/wechat/live/image/live4/ewmimg-white.png');

		$(".guest_title").attr("src","http://static.qiezipai.cn/wechat/live/image/guesttitle_w.png");

		$('.waterFall-icon').removeClass('waterFall-icon').addClass('waterFall-white-icon');
		$('.tiled-icon').removeClass('tiled-icon').addClass('tiled-white-icon');

		$('.bannerLink-tip, .puzzle, .puzzled-result, .puzzled-result-title, .puzzled-result p, .puzzled-result-hand, .puzzled-result-close, .puzzle-operate, .puzzle-button').addClass('white');
		$('.order-wrapper, .input-box--order, .order-wrapper h2, .code-button--order, .input-box--order input, .input-box--order .iconfont, .describe-wrapper p').addClass('white');
		$('.day_btn').each(function() {
			if($(this).hasClass('active')) {
				$(this).addClass('white-active')
			}else {
				$(this).addClass('white');
			}
		});

		$('.jh-container-inner, #title-jh, .jh-close, .jh-button, .banner, .banner-noImg, .activityDate, .activityDetail-button, .activityDetail-icon').addClass('white');

	} else if(id_ == 3) {
		$('.picWait').addClass('picWait-white');
		$('h2').addClass('h2-wedding');
		$('.activityDetail-p').addClass('activityDetail-p-white');
		$('.time-icon').addClass('time-icon-white');
		$('.place-icon').addClass('place-icon-white');
		$('.guestMasking,.navMasking').attr('src','http://static.qiezipai.cn/wechat/live/image/live4/cusmasking-white.png');
		$('.sponsor-border').removeClass('none');
		$('.sponsorBox').addClass('sponsorBox-white');
		$('.guestBox').addClass('guestBox-white');
		$('.sponsorTitle,.guestTitle').addClass('sponsorTitle-white');
		$('.sponsorName,.guestName').addClass('sponsorName-white');
		$('.guest').css('background-image','url(http://static.qiezipai.cn/wechat/live/image/live4/guestbg-wedding.png)');
		$('.line').addClass('line-wedding');
		$('.lookButton-p').addClass('lookButton-p-white');
		$('.triggle-icon').attr('src','http://static.qiezipai.cn/wechat/live/image/live4/triggle-icon-white.png');
		$('.nav').addClass('nav-wedding');
		$('.navLi').find('.navLi-span').addClass('navLi-white');
		$('.picLoading').addClass('picLoading-white');

		$('.sponsor-container').addClass('sponsor-container-white');
		$('.guest-container').addClass('guest-container-white');
		$('.sponsor-imgBg').addClass('sponsor-imgBg-white');
		$('.sponsor-name').addClass('sponsor-name-white');
		$('.guest-name').addClass('guest-name-white');
		$('.sponsor-link').addClass('sponsor-link-white');
		$('.guest-link').addClass('guest-link-white');
		$('.close').addClass('close-white');

		$('.activityDescribe').addClass('activityDescribe-wedding');
		$('.videoWrapper').addClass('videoWrapper-wedding');
		$('.activityDescribe-p').addClass('activityDescribe-p-white');
		$('.title-span').addClass('title-span-white');
		$('.common-p').addClass('common-p-white');
		$('.cusWebSite').addClass('cusWebSite-white');
		$('.ewm-p1').addClass('ewm-p1-white');
		$('.ewm-p2').addClass('ewm-p2-white');
		$('.homeLink').addClass('homeLink-wedding');
		$('.ewmImg').attr('src','http://static.qiezipai.cn/wechat/live/image/live4/ewmimg-white.png');

		$(".guest_title").attr("src","http://static.qiezipai.cn/wechat/live/image/guesttitle_w.png");
		$('.videoBox').addClass('videoBox-white');

		$('.activityDetail').addClass('activityDetail-wedding');
		$('.activityDetail h2').html('婚礼详情');
		$('.guestWrapper h2').html('你和他们在婚礼现场');

		$('.page1').addClass('page1-wedding');
		$('.page2').css('background','#fbf2f0');
		$('.sponsor').css('background-image','url(http://static.qiezipai.cn/wechat/live/image/live4/sponsorbg-wedding.png)');
		$('.sponsorTitle').addClass('sponsorTitle-wedding');
		$('.lookNum span').eq(0).css('color','#f0aca1');
		$('.guestMasking').addClass('none');
		$('.lookButton-p').html('查看婚礼图片');
	}
}

// touch 关闭图片
function touchImg(son, father) {

	var father = father[0];
	var son = son[0];
	var parentOpacity = 1;
	var imgScale = 1;

	var iw = son.offsetWidth, ih = son.offsetHeight;
	var startY, moveY, touchAngle;

	son.addEventListener('touchstart',function(ev){
		if(ev.targetTouches.length === 1) {
			son.style.transition = '';
			son.style.webkitTransition = '';
			father.style.transition = '';
			father.style.webkitTransition = '';

			startY = ev.touches[0].clientY;
			startX = ev.touches[0].clientX;
		}
	},false)
	son.addEventListener('touchmove',function(ev){
		if(ev.targetTouches.length === 1) {
			moveY = ev.touches[0].clientY - startY;
			moveX = ev.touches[0].clientX - startX;

			parentOpacity = 1 - (Math.abs(moveY) / 500);
			imgScale = 1 - (Math.abs(moveY) / 500);

			// 触摸滑动角度
			touchAngle = Math.abs((moveY / moveX));
			if(touchAngle > 1 && dragClose) {
				son.style.webkitTransform = 'translate('+ moveX +'px, '+ moveY +'px) scale('+ imgScale +')';
				son.style.transform = 'translate('+ moveX +'px, '+ moveY +'px) scale('+ imgScale +')';
				father.style.background = 'rgba(0, 0, 0, '+ parentOpacity +')';
				$('#imgShowModal .modal_footer').fadeOut();
			}
		}

	},false)
	son.addEventListener('touchend',function(ev){
		if(touchAngle > 1 && dragClose) {
			if(Math.abs(moveY) > 130) {
				son.style.webkitTransition = 'all .5s';
				son.style.transition = 'all .5s';
				son.style.webkitTransform = 'scale(0)';
				son.style.transform = 'scale(0)';
				$('video').removeClass('none');
				$('#imgShowModal').fadeOut(200, function() {
					picLikeArr = []; //关闭时清空 自己点赞过图片的数组
					getLikes(); // 重新获取一次；
					$('#imgShowModal .modal_footer').fadeIn();
					$('.imgShowSwiper .swiper-wrapper').empty();
					picShowSwiper.destroy(false,true);
				});
				$(document).off('touchmove');
			}else {
				son.style.webkitTransform = 'translateY(0) scale(1)';
				son.style.transform = 'translateY(0) scale(1)';
				son.style.webkitTransition = 'all .2s';
				son.style.transition = 'all .2s';

				father.style.background = 'rgba(0, 0, 0, 1)';
				father.style.webkitTransition = 'all .5s';
				father.style.transition = 'all .5s';

				$('#imgShowModal .modal_footer').fadeIn();
			}
		}
	})
}

// 预加载
var arrPreLoad = [
	'http://static.qiezipai.cn/wechat/live/image/live4/lo2.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/guestbg.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/sponsorbg.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/time-icon.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/place-icon.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/plusservice.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/sectionbg.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/triggle-icon.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/cusmasking.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/title-icon.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/like.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no0.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no1.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no2.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no3.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no4.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no5.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no6.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no7.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no8.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/no9.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/enter-icon.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/timedot-icon.png',
	'http://static.qiezipai.cn/wechat/live/image/live4/ewmimg.png'
];
var obj = {
	imgs: arrPreLoad,
	loaded: function(){
		$('.masking').addClass('masking-loaded');
	}
}
loadingFun(obj);

// swiper 内部滚动
function swiperScrillInner(wrapper) {
	// swiper 内部滚动
	var startScroll, touchStart, touchCurrent;
	wrapper.slides.on('touchstart', function (e) {
		startScroll = this.scrollTop;
		touchStart = e.targetTouches[0].pageY;
	}, false);
	wrapper.slides.on('touchmove', function (e) {
		touchCurrent = e.targetTouches[0].pageY;
		var touchesDiff = touchCurrent - touchStart;
		var slide = this;
		var onlyScrolling =
		( slide.scrollHeight > slide.offsetHeight ) && //allow only when slide is scrollable
		(
			( touchesDiff < 0 && startScroll === 0 ) || //start from top edge to scroll bottom
			( touchesDiff > 0 && startScroll === ( slide.scrollHeight - slide.offsetHeight ) ) || //start from bottom edge to scroll top
			( startScroll > 0 && startScroll < ( slide.scrollHeight - slide.offsetHeight ) ) //start from the middle
		);
		if (onlyScrolling) {
			e.stopPropagation();
		}
	}, false);
}

// toast 弹层
function toast(text) {
  $('.toast p').html(text);
  $('.toast').fadeIn(100).delay(1000).fadeOut();
}

function gz() {
	$('.day_btn, .jh-container-inner').addClass('gz');
}
